﻿using System;
using System.Collections.Generic;

namespace Allegro.TaskExecution.Tasks
{
    /// <summary>
    /// Cast a predicate as a condition in a task
    /// </summary>
    public class PredicateAsCondition : IExecutionCondition
    {
        ///<summary>
        ///</summary>
        public Predicate<IExecutionContext> Predicate { get; private set; }

        ///<summary>
        ///</summary>
        ///<param name="predicate"></param>
        public PredicateAsCondition(Predicate<IExecutionContext> predicate)
        {
            Predicate = predicate;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public bool IsTrue(IExecutionContext context)
        {
            bool result = false;
            if (Predicate != null)
                result = Predicate(context);
            return result;
        }
    }
}
